<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=11"/>
<meta name="generator" content="Doxygen 1.12.0"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>NeuZephyr: nz::cuStrm::EventPool Class Reference</title>
<link rel="icon" href="NZ_logo2.png" type="image/x-icon" />
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="resize.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr id="projectrow">
  <td id="projectlogo"><img alt="Logo" src="NZ_logo2.png"/></td>
  <td id="projectalign">
   <div id="projectname">NeuZephyr
   </div>
   <div id="projectbrief">Simple DL Framework</div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.12.0 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function() { codefold.init(0); });
/* @license-end */
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="namespaces.html"><span>Namespaces</span></a></li>
      <li class="current"><a href="annotated.html"><span>Classes</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="annotated.html"><span>Class&#160;List</span></a></li>
      <li><a href="classes.html"><span>Class&#160;Index</span></a></li>
      <li><a href="inherits.html"><span>Class&#160;Hierarchy</span></a></li>
      <li><a href="functions.html"><span>Class&#160;Members</span></a></li>
    </ul>
  </div>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:d3d9a9a6595521f9666a5e94cc830dab83b65699&amp;dn=expat.txt MIT */
$(function(){ initResizable(false); });
/* @license-end */
</script>
<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><b>nz</b></li><li class="navelem"><a class="el" href="namespacenz_1_1cu_strm.html">cuStrm</a></li><li class="navelem"><a class="el" href="classnz_1_1cu_strm_1_1_event_pool.html">EventPool</a></li>  </ul>
</div>
</div><!-- top -->
<div id="doc-content">
<div class="header">
  <div class="summary">
<a href="#pub-methods">Public Member Functions</a> &#124;
<a href="classnz_1_1cu_strm_1_1_event_pool-members.html">List of all members</a>  </div>
  <div class="headertitle"><div class="title">nz::cuStrm::EventPool Class Reference</div></div>
</div><!--header-->
<div class="contents">

<p>Internal event management system for CUDA stream synchronization (Part of <a class="el" href="classnz_1_1cu_strm_1_1_stream_manager.html" title="Centralized CUDA stream and resource management system with automatic dependency tracking.">StreamManager</a>)  
 <a href="#details">More...</a></p>
<table class="memberdecls">
<tr class="heading"><td colspan="2"><h2 class="groupheader"><a id="pub-methods" name="pub-methods"></a>
Public Member Functions</h2></td></tr>
<tr class="memitem:a8c2753fbcb62f4c0c46dd66ad2950020" id="r_a8c2753fbcb62f4c0c46dd66ad2950020"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a8c2753fbcb62f4c0c46dd66ad2950020">EventPool</a> (const size_t maxEvent)</td></tr>
<tr class="memdesc:a8c2753fbcb62f4c0c46dd66ad2950020"><td class="mdescLeft">&#160;</td><td class="mdescRight">Construct an <a class="el" href="classnz_1_1cu_strm_1_1_event_pool.html" title="Internal event management system for CUDA stream synchronization (Part of StreamManager)">EventPool</a> object with a specified maximum number of events.  <br /></td></tr>
<tr class="separator:a8c2753fbcb62f4c0c46dd66ad2950020"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a78d43b63d387dadb7662168b98560e16" id="r_a78d43b63d387dadb7662168b98560e16"><td class="memItemLeft" align="right" valign="top">&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a78d43b63d387dadb7662168b98560e16">~EventPool</a> ()</td></tr>
<tr class="memdesc:a78d43b63d387dadb7662168b98560e16"><td class="mdescLeft">&#160;</td><td class="mdescRight">Destruct the <a class="el" href="classnz_1_1cu_strm_1_1_event_pool.html" title="Internal event management system for CUDA stream synchronization (Part of StreamManager)">EventPool</a> object, releasing all managed CUDA events.  <br /></td></tr>
<tr class="separator:a78d43b63d387dadb7662168b98560e16"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a7cdb0eb8403303e52ad5cc5f6e2d0737" id="r_a7cdb0eb8403303e52ad5cc5f6e2d0737"><td class="memItemLeft" align="right" valign="top">cudaEvent_t&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a7cdb0eb8403303e52ad5cc5f6e2d0737">recordData</a> (cudaStream_t stream, void *data)</td></tr>
<tr class="memdesc:a7cdb0eb8403303e52ad5cc5f6e2d0737"><td class="mdescLeft">&#160;</td><td class="mdescRight">Record an event in a CUDA stream associated with a given data pointer.  <br /></td></tr>
<tr class="separator:a7cdb0eb8403303e52ad5cc5f6e2d0737"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:ac850289a3ad016430ab5b5a497f0eb19" id="r_ac850289a3ad016430ab5b5a497f0eb19"><td class="memItemLeft" align="right" valign="top">std::unordered_set&lt; cudaEvent_t &gt;&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#ac850289a3ad016430ab5b5a497f0eb19">getEvents</a> (void *data)</td></tr>
<tr class="memdesc:ac850289a3ad016430ab5b5a497f0eb19"><td class="mdescLeft">&#160;</td><td class="mdescRight">Retrieve all CUDA events associated with a given data pointer.  <br /></td></tr>
<tr class="separator:ac850289a3ad016430ab5b5a497f0eb19"><td class="memSeparator" colspan="2">&#160;</td></tr>
<tr class="memitem:a42536c96100f953868f17998a55d8543" id="r_a42536c96100f953868f17998a55d8543"><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="#a42536c96100f953868f17998a55d8543">syncData</a> (void *data)</td></tr>
<tr class="memdesc:a42536c96100f953868f17998a55d8543"><td class="mdescLeft">&#160;</td><td class="mdescRight">Synchronize the program execution with the completion of all events associated with a given data pointer.  <br /></td></tr>
<tr class="separator:a42536c96100f953868f17998a55d8543"><td class="memSeparator" colspan="2">&#160;</td></tr>
</table>
<a name="details" id="details"></a><h2 class="groupheader">Detailed Description</h2>
<div class="textblock"><p>Internal event management system for CUDA stream synchronization (Part of <a class="el" href="classnz_1_1cu_strm_1_1_stream_manager.html" title="Centralized CUDA stream and resource management system with automatic dependency tracking.">StreamManager</a>) </p>
<p>This class implements a thread-safe CUDA event pool with automatic recycling and data-aware synchronization capabilities. It serves as the foundational event infrastructure for <a class="el" href="classnz_1_1cu_strm_1_1_stream_manager.html" title="Centralized CUDA stream and resource management system with automatic dependency tracking.">nz::cuStrm::StreamManager</a>'s operation scheduling system.</p>
<dl class="section warning"><dt>Warning</dt><dd><ul>
<li><b>This class must not be directly instantiated or invoked</b></li>
<li>Event lifecycle management should <b>exclusively</b> be handled through <a class="el" href="classnz_1_1cu_strm_1_1_stream_manager.html" title="Centralized CUDA stream and resource management system with automatic dependency tracking.">StreamManager</a> interfaces</li>
<li>Direct usage may lead to:<ul>
<li>Undefined synchronization behavior</li>
<li>Event pool corruption</li>
<li>CUDA resource leaks</li>
</ul>
</li>
</ul>
</dd></dl>
<h3><a class="anchor" id="autotoc_md39"></a>
Core Functionality:</h3>
<ul>
<li><b>Pool Management</b>:<ul>
<li>Pre-allocates <code>cudaEventDisableTiming</code> events during initialization</li>
<li>Dynamically expands when concurrent demands exceed initial capacity</li>
<li>Implements triple-state tracking (free/busy/released) with atomic transfers</li>
</ul>
</li>
<li><b>Data-Event Binding</b>:<ul>
<li>Maintains bidirectional mappings between CUDA events and user data pointers</li>
<li>Enables data-centric synchronization through <code><a class="el" href="#a42536c96100f953868f17998a55d8543" title="Synchronize the program execution with the completion of all events associated with a given data poin...">syncData()</a></code></li>
</ul>
</li>
<li><b>Automatic Recycling</b>:<ul>
<li>Utilizes CUDA stream callbacks for event release detection</li>
<li>Implements lock-protected resource transitions between states</li>
</ul>
</li>
</ul>
<h3><a class="anchor" id="autotoc_md40"></a>
Critical Methods (Internal Use Only):</h3>
<ul>
<li><code><a class="el" href="#a7cdb0eb8403303e52ad5cc5f6e2d0737" title="Record an event in a CUDA stream associated with a given data pointer.">recordData()</a></code>:<ul>
<li>Binds event recording to specific data pointer</li>
<li>Triggers automatic recycling via stream callback</li>
</ul>
</li>
<li><code><a class="el" href="#ac850289a3ad016430ab5b5a497f0eb19" title="Retrieve all CUDA events associated with a given data pointer.">getEvents()</a></code>:<ul>
<li>Retrieves all events associated with data pointer</li>
<li>Used for dependency graph construction</li>
</ul>
</li>
<li><code><a class="el" href="#a42536c96100f953868f17998a55d8543" title="Synchronize the program execution with the completion of all events associated with a given data poin...">syncData()</a></code>:<ul>
<li>Blocks until all events linked to data complete</li>
<li>Implements condition variable-based waiting</li>
</ul>
</li>
</ul>
<p>The pool maintains three distinct event states to ensure safe CUDA event reuse:</p>
<ul>
<li><b>Free Pool</b>: Contains immediately available <code>cudaEvent_t</code> instances ready for allocation. Events are drawn from this pool when servicing new recording requests through <code>acquire()</code>.</li>
<li><b>Busy Pool</b>: Tracks actively used events currently associated with in-flight CUDA operations. Events remain here until their host stream completes execution, at which point the stream callback moves them to the released state.</li>
<li><b>Released Pool</b>: Holds events that have completed execution but haven't been recycled. These events are transferred back to the free pool during subsequent <code>acquire()</code> calls via the internal <code>transfer()</code> method, ensuring safe temporal separation between event usage cycles and preventing premature reuse.</li>
</ul>
<dl class="section note"><dt>Note</dt><dd><ol type="1">
<li>All public methods employ <code>std::lock_guard</code> for thread safety</li>
<li>Event destruction occurs only during pool destruction</li>
<li>Exceeding maxEvent capacity triggers silent pool expansion</li>
<li>Callback parameters use heap-allocated memory for cross-stream safety </li>
</ol>
</dd></dl>

<p class="definition">Definition at line <a class="el" href="_event_pool_8cuh_source.html#l00165">165</a> of file <a class="el" href="_event_pool_8cuh_source.html">EventPool.cuh</a>.</p>
</div><h2 class="groupheader">Constructor &amp; Destructor Documentation</h2>
<a id="a8c2753fbcb62f4c0c46dd66ad2950020" name="a8c2753fbcb62f4c0c46dd66ad2950020"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a8c2753fbcb62f4c0c46dd66ad2950020">&#9670;&#160;</a></span>EventPool()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">nz::cuStrm::EventPool::EventPool </td>
          <td>(</td>
          <td class="paramtype">const size_t</td>          <td class="paramname"><span class="paramname"><em>maxEvent</em></span></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span><span class="mlabel">explicit</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Construct an <a class="el" href="classnz_1_1cu_strm_1_1_event_pool.html" title="Internal event management system for CUDA stream synchronization (Part of StreamManager)">EventPool</a> object with a specified maximum number of events. </p>
<p>This constructor initializes an <a class="el" href="classnz_1_1cu_strm_1_1_event_pool.html" title="Internal event management system for CUDA stream synchronization (Part of StreamManager)">EventPool</a> object with a given maximum number of CUDA events. It creates <code>maxEvent</code> number of CUDA events with the <code>cudaEventDisableTiming</code> flag and inserts them into the <code>free</code> set, indicating that these events are initially available for use.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">maxEvent</td><td>The maximum number of CUDA events that the <a class="el" href="classnz_1_1cu_strm_1_1_event_pool.html" title="Internal event management system for CUDA stream synchronization (Part of StreamManager)">EventPool</a> can manage. Memory location: host.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>None</dd></dl>
<p>Memory management: The constructor allocates memory for CUDA events using <code>cudaEventCreateWithFlags</code>. The responsibility of deallocating these events lies with the destructor of the <code><a class="el" href="classnz_1_1cu_strm_1_1_event_pool.html" title="Internal event management system for CUDA stream synchronization (Part of StreamManager)">EventPool</a></code> class. Exception handling: This constructor does not have an explicit exception - handling mechanism. It relies on the CUDA runtime to report any errors that occur during event creation. If an error occurs during <code>cudaEventCreateWithFlags</code>, the program's behavior may be undefined. Relationship with other components: This constructor is part of the <code><a class="el" href="classnz_1_1cu_strm_1_1_event_pool.html" title="Internal event management system for CUDA stream synchronization (Part of StreamManager)">EventPool</a></code> class, which is likely used in a larger CUDA - related application to manage the lifecycle of CUDA events.</p>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>The time complexity of this constructor is O(n), where n is the value of <code>maxEvent</code>, as it iterates <code>maxEvent</code> times to create and insert events.</li>
<li>Ensure that the CUDA environment is properly initialized before creating an <code><a class="el" href="classnz_1_1cu_strm_1_1_event_pool.html" title="Internal event management system for CUDA stream synchronization (Part of StreamManager)">EventPool</a></code> object.</li>
</ul>
</dd></dl>
<div class="fragment"><div class="line">```cpp</div>
<div class="line"><span class="keywordtype">size_t</span> maxEvents = 10;</div>
<div class="line"><a class="code hl_class" href="classnz_1_1cu_strm_1_1_event_pool.html">EventPool</a> pool(maxEvents);</div>
<div class="line">```</div>
<div class="ttc" id="aclassnz_1_1cu_strm_1_1_event_pool_html"><div class="ttname"><a href="classnz_1_1cu_strm_1_1_event_pool.html">nz::cuStrm::EventPool</a></div><div class="ttdoc">Internal event management system for CUDA stream synchronization (Part of StreamManager)</div><div class="ttdef"><b>Definition</b> <a href="_event_pool_8cuh_source.html#l00165">EventPool.cuh:165</a></div></div>
</div><!-- fragment --> 
<p class="definition">Definition at line <a class="el" href="_event_pool_8cuh_source.html#l00191">191</a> of file <a class="el" href="_event_pool_8cuh_source.html">EventPool.cuh</a>.</p>

</div>
</div>
<a id="a78d43b63d387dadb7662168b98560e16" name="a78d43b63d387dadb7662168b98560e16"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a78d43b63d387dadb7662168b98560e16">&#9670;&#160;</a></span>~EventPool()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">nz::cuStrm::EventPool::~EventPool </td>
          <td>(</td>
          <td class="paramname"><span class="paramname"><em></em></span></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Destruct the <a class="el" href="classnz_1_1cu_strm_1_1_event_pool.html" title="Internal event management system for CUDA stream synchronization (Part of StreamManager)">EventPool</a> object, releasing all managed CUDA events. </p>
<p>This destructor iterates through the sets of free, busy, and released CUDA events and destroys each event using <code>cudaEventDestroy</code>. This ensures that all resources allocated for these events are properly released.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">None</td><td></td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>None</dd></dl>
<p>Memory management: The destructor is responsible for deallocating the memory associated with the CUDA events that were created during the lifetime of the <code><a class="el" href="classnz_1_1cu_strm_1_1_event_pool.html" title="Internal event management system for CUDA stream synchronization (Part of StreamManager)">EventPool</a></code> object. It destroys all events in the <code>free</code>, <code>busy</code>, and <code>released</code> sets. Exception handling: This destructor does not have an explicit exception - handling mechanism. It relies on the CUDA runtime to report any errors that occur during event destruction. If an error occurs during <code>cudaEventDestroy</code>, the program's behavior may be undefined. Relationship with other components: This destructor is part of the <code><a class="el" href="classnz_1_1cu_strm_1_1_event_pool.html" title="Internal event management system for CUDA stream synchronization (Part of StreamManager)">EventPool</a></code> class and is crucial for proper resource management in a CUDA - related application that uses the <code><a class="el" href="classnz_1_1cu_strm_1_1_event_pool.html" title="Internal event management system for CUDA stream synchronization (Part of StreamManager)">EventPool</a></code> to manage CUDA events.</p>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>The time complexity of this destructor is O(n), where n is the total number of events in the <code>free</code>, <code>busy</code>, and <code>released</code> sets combined.</li>
<li>Ensure that all CUDA operations associated with the events have completed before the <code><a class="el" href="classnz_1_1cu_strm_1_1_event_pool.html" title="Internal event management system for CUDA stream synchronization (Part of StreamManager)">EventPool</a></code> object is destroyed.</li>
</ul>
</dd></dl>
<div class="fragment"><div class="line">```cpp</div>
<div class="line"><span class="comment">// Assume EventPool is defined and an instance is created</span></div>
<div class="line"><a class="code hl_class" href="classnz_1_1cu_strm_1_1_event_pool.html">EventPool</a> pool(10);</div>
<div class="line"><span class="comment">// Some operations with the pool</span></div>
<div class="line"><span class="comment">// ...</span></div>
<div class="line"><span class="comment">// The pool will be destroyed automatically when it goes out of scope</span></div>
<div class="line">```</div>
</div><!-- fragment --> 
<p class="definition">Definition at line <a class="el" href="_event_pool_8cuh_source.html#l00226">226</a> of file <a class="el" href="_event_pool_8cuh_source.html">EventPool.cuh</a>.</p>

</div>
</div>
<h2 class="groupheader">Member Function Documentation</h2>
<a id="ac850289a3ad016430ab5b5a497f0eb19" name="ac850289a3ad016430ab5b5a497f0eb19"></a>
<h2 class="memtitle"><span class="permalink"><a href="#ac850289a3ad016430ab5b5a497f0eb19">&#9670;&#160;</a></span>getEvents()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">std::unordered_set&lt; cudaEvent_t &gt; nz::cuStrm::EventPool::getEvents </td>
          <td>(</td>
          <td class="paramtype">void *</td>          <td class="paramname"><span class="paramname"><em>data</em></span></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Retrieve all CUDA events associated with a given data pointer. </p>
<p>This function searches for the provided data pointer in the internal mapping and returns a set of all CUDA events associated with it. If no events are found for the given data pointer, an empty set is returned.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">data</td><td>A pointer to the data for which the associated events are to be retrieved. Memory location: host or device, depending on the context.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>An unordered set of CUDA event handles associated with the given data pointer. If no events are associated, an empty set is returned.</dd></dl>
<p>Memory management: The function does not allocate or deallocate any memory directly. It only accesses the internal mapping data structure of the <code><a class="el" href="classnz_1_1cu_strm_1_1_event_pool.html" title="Internal event management system for CUDA stream synchronization (Part of StreamManager)">EventPool</a></code> class. Exception handling: This function does not have an explicit exception - handling mechanism. It relies on the underlying standard library functions for <code>std::unordered_map</code> operations. If an error occurs during the map lookup, the program's behavior may be undefined. Relationship with other components: This function is part of the <code><a class="el" href="classnz_1_1cu_strm_1_1_event_pool.html" title="Internal event management system for CUDA stream synchronization (Part of StreamManager)">EventPool</a></code> class. It interacts with the internal <code>eventMap</code> data structure to retrieve the associated events.</p>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>The average time complexity of this function is O(1) because it uses an <code>std::unordered_map</code> for lookup. In the worst - case scenario, the time complexity is O(n), where n is the number of elements in the <code>eventMap</code>.</li>
<li>Ensure that the data pointer is valid and has been previously used in the <code>recordData</code> function to associate events with it. </li>
</ul>
</dd></dl>

<p class="definition">Definition at line <a class="el" href="_event_pool_8cuh_source.html#l00282">282</a> of file <a class="el" href="_event_pool_8cuh_source.html">EventPool.cuh</a>.</p>

</div>
</div>
<a id="a7cdb0eb8403303e52ad5cc5f6e2d0737" name="a7cdb0eb8403303e52ad5cc5f6e2d0737"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a7cdb0eb8403303e52ad5cc5f6e2d0737">&#9670;&#160;</a></span>recordData()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">cudaEvent_t nz::cuStrm::EventPool::recordData </td>
          <td>(</td>
          <td class="paramtype">cudaStream_t</td>          <td class="paramname"><span class="paramname"><em>stream</em></span>, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">void *</td>          <td class="paramname"><span class="paramname"><em>data</em></span>&#160;)</td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Record an event in a CUDA stream associated with a given data pointer. </p>
<p>This function records a CUDA event in the specified CUDA stream and associates it with the provided data pointer. It first acquires an available event from the event pool, then updates the mapping between data pointers and events and vice - versa. Finally, it records the event in the stream and returns the event handle.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">stream</td><td>The CUDA stream in which the event will be recorded. Memory location: host. </td></tr>
    <tr><td class="paramname">data</td><td>A pointer to the data associated with the event. Memory location: host or device, depending on the context.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>A handle to the recorded CUDA event.</dd></dl>
<p>Memory management: The function does not allocate or deallocate any memory directly. It uses an existing event pool and updates mapping data structures. The responsibility of event memory management lies with the event pool's constructor and destructor. Exception handling: This function does not have an explicit exception - handling mechanism. It relies on the underlying CUDA functions (such as <code>acquire</code> and <code>record</code>) to report any errors. If an error occurs during event acquisition or recording, the program's behavior may be undefined. Relationship with other components: This function is part of the <code><a class="el" href="classnz_1_1cu_strm_1_1_event_pool.html" title="Internal event management system for CUDA stream synchronization (Part of StreamManager)">EventPool</a></code> class. It interacts with the event pool's internal state (event sets and mapping data structures) and the CUDA runtime to record events.</p>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>The time complexity of this function is O(log n) due to the operations on the mapping data structures (assuming they are implemented as balanced trees), where n is the number of elements in the mapping.</li>
<li>Ensure that the CUDA stream is properly initialized before calling this function. </li>
</ul>
</dd></dl>

<p class="definition">Definition at line <a class="el" href="_event_pool_8cuh_source.html#l00256">256</a> of file <a class="el" href="_event_pool_8cuh_source.html">EventPool.cuh</a>.</p>

</div>
</div>
<a id="a42536c96100f953868f17998a55d8543" name="a42536c96100f953868f17998a55d8543"></a>
<h2 class="memtitle"><span class="permalink"><a href="#a42536c96100f953868f17998a55d8543">&#9670;&#160;</a></span>syncData()</h2>

<div class="memitem">
<div class="memproto">
<table class="mlabels">
  <tr>
  <td class="mlabels-left">
      <table class="memname">
        <tr>
          <td class="memname">void nz::cuStrm::EventPool::syncData </td>
          <td>(</td>
          <td class="paramtype">void *</td>          <td class="paramname"><span class="paramname"><em>data</em></span></td><td>)</td>
          <td></td>
        </tr>
      </table>
  </td>
  <td class="mlabels-right">
<span class="mlabels"><span class="mlabel">inline</span></span>  </td>
  </tr>
</table>
</div><div class="memdoc">

<p>Synchronize the program execution with the completion of all events associated with a given data pointer. </p>
<p>This function waits until all CUDA events associated with the provided data pointer have completed. It uses a condition variable (<code>cv</code>) to block the current thread until the <code>eventMap</code> no longer contains any events for the given data pointer, indicating that all associated events have finished.</p>
<dl class="params"><dt>Parameters</dt><dd>
  <table class="params">
    <tr><td class="paramname">data</td><td>A pointer to the data for which the associated events need to be synchronized. Memory location: host or device, depending on the context.</td></tr>
  </table>
  </dd>
</dl>
<dl class="section return"><dt>Returns</dt><dd>None.</dd></dl>
<p>Memory management: The function does not allocate or deallocate any memory directly. It only accesses the internal <code>eventMap</code> data structure of the <code><a class="el" href="classnz_1_1cu_strm_1_1_event_pool.html" title="Internal event management system for CUDA stream synchronization (Part of StreamManager)">EventPool</a></code> class. Exception handling: This function does not have an explicit exception - handling mechanism. It relies on the underlying standard library functions for mutex and condition variable operations. If an error occurs during locking, unlocking, or waiting, the program's behavior may be undefined. Relationship with other components: This function is part of the <code><a class="el" href="classnz_1_1cu_strm_1_1_event_pool.html" title="Internal event management system for CUDA stream synchronization (Part of StreamManager)">EventPool</a></code> class. It interacts with the internal <code>eventMap</code> data structure and the condition variable (<code>cv</code>) to wait for event completion.</p>
<dl class="section note"><dt>Note</dt><dd><ul>
<li>The time complexity of this function is not fixed as it depends on when the associated events complete. It will block until all relevant events are finished.</li>
<li>Ensure that the data pointer is valid and has been previously used in the <code>recordData</code> function to associate events with it.</li>
<li>The function assumes that the internal state of the <code>eventMap</code> is updated correctly when events are completed to signal the condition variable. </li>
</ul>
</dd></dl>

<p class="definition">Definition at line <a class="el" href="_event_pool_8cuh_source.html#l00309">309</a> of file <a class="el" href="_event_pool_8cuh_source.html">EventPool.cuh</a>.</p>

</div>
</div>
<hr/>The documentation for this class was generated from the following file:<ul>
<li>D:/Users/Mgepahmge/Documents/C Program/NeuZephyr/include/NeuZephyr/<a class="el" href="_event_pool_8cuh_source.html">EventPool.cuh</a></li>
</ul>
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="doxygen.svg" width="104" height="31" alt="doxygen"/></a> 1.12.0
</small></address>
</div><!-- doc-content -->
</body>
</html>
